<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="commons/taglib.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="${ctx }/static/css/pintuer.css">
<link rel="stylesheet" href="${ctx }/static/css/admin.css">
<script type="text/javascript"
	src="${ctx }/static/js/jquery-1.8.2.min.js"></script>
<script src="${ctx }/static/js/jquery.js"></script>
<script src="${ctx }/static/js/pintuer.js"></script>
<%-- <script type="text/javascript">
	<%if (session.getAttribute("loginMessage") == null) {%>
		alert("请登录后访问！");                        /*  验证是否存在ID，若没有表示没登录 */
	 	/* window.location.href='login'; */
	 	window.parent.location.href='${ctx }/login';
	<%}%>
	</script> --%>
</head>
<body>
	<form method="post" action="excel">
		<div class="panel admin-panel">
			<div class="panel-head">
				<strong class="icon-reorder"> 病历管理</strong>
				<button id="js-export" type="submit" class="btn btn-primary"
					style="float: right; margin-right: 100px">导出Excel</button>
			</div>
			<div class="panel admin-panel" style="height: 40px;">
				<input type="text" id="message" value=""
					style="width: 30%; height: 40px; border: 1px solid #09c; border-radius: 5px; font-size: 18px;">
				<button id="query" type="button"
					style="width: 60px; height: 40px; border: 1px solid #09c; border-radius: 5px; font-size: 18px;">搜索</button>
			</div>


			<table id="case" class="table table-hover text-center">
				<tr>
					<th width="120">ID</th>
					<th>医院名</th>
					<th>疾病</th>
					<th>处方</th>
					<th>金额</th>
					<th width="120">时间</th>
					<th>操作</th>
				</tr>

				<c:forEach items="${ caseHistery }" var="caseHistery">
					<tr class="tr">
						<td><input type="checkbox" name="id[]"
							value="${caseHistery.branchCourts}" /><input type="hidden"
							name="id" value="${caseHistery.id }" /> ${caseHistery.id }</td>
						<td><input type="hidden" name="branchCourts"
							value="${caseHistery.branchCourts }" />${caseHistery.branchCourts }</td>
						<td><input type="hidden" name="disease"
							value="${caseHistery.disease }" />${caseHistery.disease }</td>
						<td><input type="hidden" name="drug"
							value="${caseHistery.drug }" />${caseHistery.drug }</td>
						<td><input type="hidden" name="payment"
							value="${caseHistery.payment }" />${caseHistery.payment }</td>
						<td><input type="hidden" name="date"
							value="${caseHistery.date }" />${caseHistery.date }</td>
						<td><div class="button-group">
								<a class="button border-red" href="javascript:void(0)"
									onclick="return del(${caseHistery.id})"><span
									class="icon-trash-o"></span> 删除</a>
							</div></td>
					</tr>
				</c:forEach>

				<!-- <tr>
          <td><input type="checkbox" name="id[]" value="1" />
            1</td>
          <td>神夜</td>
          <td>13420925611</td>
          <td>564379992@qq.com</td>  
           <td>深圳市民治街道</td>         
          <td>这是一套后台UI，喜欢的朋友请多多支持谢谢。</td>
          <td>2016-07-01</td>
          <td><div class="button-group"> <a class="button border-red" href="javascript:void(0)" onclick="return del(1)"><span class="icon-trash-o"></span> 删除</a> </div></td>
        </tr> -->

				<tr id="tr1">
					<td colspan="8"><div class="pagelist">
							<a href="caseHistery?pageNumber=1">首页</a>
							<c:if test="${pageNumber>1 }">

								<a href="caseHistery?pageNumber=${pageNumber-1 }">上一页</a>
							</c:if>
							<c:if test="${pageNumber>2 }">
                        		....
                        	</c:if>
							<c:if test="${pageNumber>1 }">
								<a href="caseHistery?pageNumber=${pageNumber-1 }">${pageNumber-1 }</a>
							</c:if>

							<c:if test="${pageNumber<pages }">
								<a href="caseHistery?pageNumber=${pageNumber+1 }">下一页</a>
							</c:if>

							<a href="caseHistery?pageNumber=${pages }">末页</a> <span>&nbsp;&nbsp;第${pageNumber}页&nbsp;共${pages }页</span>
						</div></td>
				</tr>
			</table>
		</div>
	</form>
	<script type="text/javascript">

function del(id){
	if(confirm("删除后的数据不可恢复，请慎重选择！")){
		window.location.href="deleCaseHistery?id=" + id;       
		//通过confirm来跳转页面,并传入对应的id
	}
}

$("#checkall").click(function(){ 
  $("input[name='id[]']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

function DelSelect(){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		var t=confirm("删除后的数据不可恢复，请慎重选择！？");
		if (t==false) return false; 		
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}

$("#query").click(function() {
	$(".tr").remove();
	$("#tr1").empty();
	console.log($("#message").val());
	$.post('queryMes',{
		mes:$("#message").val()
	},function(e) {
		console.log(e);
		var li = e.list;
		  for(var i=0; i<li.length;i++){
		$("#case").append("<tr class=tr id='xs'>"+
			"<td>"+li[i].id+"</td>"+
			"<td>"+li[i].branchCourts+"</td>"+
			"<td>"+li[i].disease+"</td>"+
			"<td>"+li[i].drug+"</td>"+
			"<td>"+li[i].payment+"</td>"+
			"<td>"+li[i].date+"</td>"+
			"<td>"+"<div class='button-group'><a class='button border-red' href='javascript:void(0)'onclick='return del("+li[i].id+")'><span class='icon-trash-o'>删除</span>"+"</a></div></td>"+
			"</tr>");
		}
	$("#case").append("<tr class=tr id='xd'>"+
			"<td colspan='8'><div class='pagelist'>"+
			"<button type='button' style='margin-right:10px;' onclick='fy(1)' id='before' value='${pageNumber }' >上一页</button>"+
			"<button type='button' style='margin-right:10px;' onclick='fy(2)' id='after' value='${pageNumber }' >下一页</button>"+
			"</div></td>"+
			"</tr>");  
	
	})
})


</script>
 <script type="text/javascript">
	function fy(a) {
		$('#case #xs').remove();
		var pa;
		if (a==1) {
			var p=$('#before').val();
			if (p==1) {
				$('#before').html('首页');
			}else {
				pa=p-1;
			}
		}
		if (a==2) {
			var p=$('#after').val();
			if (p=='${pages}') {
				$('#before').html('末页');
			}else {
				pa=parseInt(p)+1;
			}
		}
		if(a==null) {
			pa=1;
		}
		$.post('queryMes1',{
			mes:$("#message").val(),
			pageNumber:pa
		},function(e) {
			var page = e.page.list;
			console.log(page.length);
			for(var i=0; i<page.length;i++){  
		$("#case").append("<tr class=tr>"+
			"<td>"+page[i].id+"</td>"+
			"<td>"+page[i].branchCourts+"</td>"+
			"<td>"+page[i].disease+"</td>"+
			"<td>"+page[i].drug+"</td>"+
			"<td>"+page[i].payment+"</td>"+
			"<td>"+page[i].date+"</td>"+
			"<td>"+"<div class='button-group'><a class='button border-red' href='javascript:void(0)'onclick='return del("+page[i].id+")'><span class='icon-trash-o'>删除</span>"+"</a></div></td>"+
			"</tr>");
		}
			
		$("#case").append("<tr class=tr>"+
				"<td colspan='8'><div class='pagelist'>"+
				"<button type='button' style='margin-right:10px;' onclick='fx(1)' id='before' value='${pageNumber-1 }' >上一页</button>"+
				"<button type='button' style='margin-right:10px;' onclick='fx(2)' id='after' value='${pageNumber+1 }' >下一页</button>"+
				"</div></td>"+
				"</tr>"); 
			fx(e);
		$('#case #xd').remove();
		
		})
	} 
	var i=0;
	function fx(a){
		$('#case #xs').remove();
		var pa;
		if (a==1) {
			var p=$('#before').val();
			if (p==1) {
				$('#before').html('首页');
			}else {
				pa=p-1;
			}
		}
		if (a==2) {
			var p=$('#after').val();
			if (p=='${pages}') {
				$('#before').html('末页');
			}else {
				pa=parseInt(p)+1;
			}
		}
		if(a==null) {
			pa=1;
		}
		i++;
		if(i%2==0){
			$('.tr').remove();
			$.post('queryMes1',{
				mes:$("#message").val(),
				pageNumber:pa
			},function(e) {
				var page = e.page.list;
				console.log(page.length);
				for(var i=0; i<page.length;i++){  
			$("#case").append("<tr class=tr>"+
				"<td>"+page[i].id+"</td>"+
				"<td>"+page[i].branchCourts+"</td>"+
				"<td>"+page[i].disease+"</td>"+
				"<td>"+page[i].drug+"</td>"+
				"<td>"+page[i].payment+"</td>"+
				"<td>"+page[i].date+"</td>"+
				"<td>"+"<div class='button-group'><a class='button border-red' href='javascript:void(0)'onclick='return del("+page[i].id+")'><span class='icon-trash-o'>删除</span>"+"</a></div></td>"+
				"</tr>");
			}
				$("#case").append("<tr class=tr>"+
						"<td colspan='8'><div class='pagelist'>"+
						"<button type='button' style='margin-right:10px;' onclick='fx(1)' id='before' value='${pageNumber-1 }' >上一页</button>"+
						"<button type='button' style='margin-right:10px;' onclick='fx(2)' id='after' value='${pageNumber+1 }' >下一页</button>"+
						"</div></td>"+
						"</tr>"); 
					fx(e);
				}
				);
		}
	}
 </script> 
</body>
</html>